import numpy as np
import time
from functools import wraps

def fn_timer(function):
    @wraps(function)
    def function_timer(*args, **kwargs):
        t0 = time.time()
        result = function(*args, **kwargs)
        t1 = time.time()
        print("Total time running :" + str(t1 - t0)+"seconds" )
        return result
    return function_timer

def get_pivot(L,left,right):
    # pivot	[ˈpɪvət]
    # n.支点; 枢轴; 中心点; 最重要的人(或事物); 中心; 核心;
    medium = int((left+right)/2)
    if L[left] > L[medium]:
        L[left] , L[medium] = L[medium] , L[left]
    if L[left] > L[right]:
        L[left], L[right] = L[right], L[left]
    if L[medium] > L[right]:
        L[right] , L[medium] = L[medium], L[right]
    L[right-1], L[medium] = L[medium], L[right-1]
    return L[right-1]

def quick_sort(L,left,right):
    if right - left > 1 :
        pivot = get_pivot(L,left,right)
        low = left + 1
        high = right - 2
        while True :
            if L[high] > pivot :
                high -= 1
            if L[low] < pivot:
                low += 1
            if low <= high :
                L[high] , L[low] =  L[low] ,L[high]
            else:break
        L[low], L[right-1] =  L[right-1],L[low]
        quick_sort(L,left,low-1)
        quick_sort(L,low+1,right)
    elif L[right] < L[left]:
         L[right], L[left] =  L[left] ,L[right]



if __name__ == '__main__':
    # n =
    # 40,8,54,76,91
    g = np.random.randint(0, 100, 50)
    n = (g).tolist()
    quick_sort(n,0,len(n)-1)

# 能用是能用但是数据量一大就有问题了，我在发觉发掘，肯定是哪里写的不好

